<?php

	/**
	 * Hikle date handling class.
	 */
	class Date{
		private $year;
		private $month;
		private $day;
		private $hour;
		private $minute;
		private $second;
		private $weekNr;
		
		// to unix.
		private $unix;
	
		public function __construct($year, $month, $day, $hour, $minute, $second = 0){
			$this->year = $year;
			$this->month = $month;
			$this->day = $day;
			$this->hour = $hour;
			$this->minute = $minute;
			$this->second = $second;
			$this->setUnix();
		}
		
		private function setUnix(){
			$this->unix = mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
			$this->weekNr = date('W', mktime(0, 0, 0, $this->month, $this->day, $this->year));
		}
		
		public function setHour($h){
			$this->hour = $h;
			$this->setUnix();
		}
		
		public function setMinute($m){
			$this->minute = $m;
			$this->setUnix();
		}
		
		public function getUnix(){
			return $this->unix;
		}
		
		public function isInFuture($buffer){
			if($this->unix >= strtotime($buffer)){
				return true;
			}
			
			return false;
		}
		
		public function isInNextWeek(){
			if($this->weekNr === date('W') + 1){
				return true;
			}
		}
		
		public function getDay(){
			$str = $this->day;
			
			// Let's not add any zero's.
			if(strlen($str) === 2){
				if($str[0] === '0'){
					$str = $str[1];
				}
			}
		
			return $str;
		}
		
		public function isInPrevWeek(){
			if($this->weekNr === date('W') - 1){
				return true;
			}
		}
		
		public function isInCurrentWeek(){
			if($this->weekNr === date('W')){
				return true;
			}
		}
		
		public function isInCurrentYear(){
			if($this->year !== date('Y')){
				return false;
			}
			
			return true;
		}
		
		public function getYear(){
			return $this->year;
		}
		
		public function getMonthString($lang = 'nl'){
			switch($this->month){
				case 1:
					return 'januari';
				case 2:
					return 'februari';
				case 3:
					return 'maart';
				case 4:
					return 'april';
				case 5:
					return 'mei';
				case 6:
					return 'juni';
				case 7:
					return 'juli';
				case 8:
					return 'augustus';
				case 9:
					return 'september';
				case 10:
					return 'oktober';
				case 11:
					return 'november';
				case 12:
					return 'december';
			}
		}
		
		public function dayToString($lang = 'nl'){
			$dayString = date('N', $this->unix);
			
			switch($dayString){
				case 1:
					return 'maandag';
				case 2:
					return 'dinsdag';
				case 3:
					return 'woensdag';
				case 4:
					return 'donderdag';
				case 5:
					return 'vrijdag';
				case 6:
					return 'zaterdag';
				case 7:
					return 'zondag';
			}
		}
			
		public function isToday(){
			if(mktime(0, 0, 0, $this->month, $this->day, $this->year) === mktime(0, 0, 0, date('m')  , date('d'), date('Y'))){
				return true;
			}
			
			return false;
		}
		
		public function isTomorrow(){
			if(mktime(0, 0, 0, $this->month, $this->day, $this->year) === mktime(0, 0, 0, date('m')  , date('d') + 1, date('Y'))){
				return true;
			}
			
			return false;
		}
		
		public function isDayAfterTomorrow(){
			if(mktime(0, 0, 0, $this->month, $this->day, $this->year) === mktime(0, 0, 0, date('m')  , date('d') + 2, date('Y'))){
				return true;
			}
			
			return false;
		}
		
		public function isYesterday(){
			if(mktime(0, 0, 0, $this->month, $this->day, $this->year) === mktime(0, 0, 0, date('m')  , date('d') - 1, date('Y'))){
				return true;
			}
			
			return false;
		}
		
		public function isDayBeforeYesterday(){
			if(mktime(0, 0, 0, $this->month, $this->day, $this->year) === mktime(0, 0, 0, date('m')  , date('d') - 2, date('Y'))){
				return true;
			}
			
			return false;
		}
		
		public function isAfter($compareDate){
			if($this->unix > $compareDate->getUnix()){
				return true;
			}
			
			return false;
		}
		
		public function toMysqlDate(){
			return $this->year . '-' . $this->month . '-' . $this->day;
		}
		
		public function toMysqlTime(){
			return $this->hour . ':' . $this->second;
		}
	}

// File end.